<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <?php
        include "includes/ketnoi.php";
        include "includes/header.php";
        ?>
        <style type="text/css">
            .example{
                margin: 20px;
            }
        </style>
    </head>
    <body>
        <?php
        // put your code here
//        $email = "";
//        if (isset($_POST["btnDN"])) {
//            $email = $_POST["txtEmail"];
//            $mk = $_POST["txtMK"];
            $sql = "SELECT * FROM users where id=2";
            if (!$conn->query($sql)) {
                die("loi");
            } else {
                $TT = mysqli_fetch_all($conn->query($sql), MYSQLI_ASSOC);
                foreach ($TT as $LayTT) {
                    $LayTT["fname"];
                }
            }
//        }
            if (isset($_POST['btnLuu'])) {
            $Ngay = date("d-m-y") . ' ' . date('h-i');
            $FirtN = $_POST["txtFirtName"];
            $LastN = $_POST["txtLastName"];
            $idLocation = $_POST["id"];
            if ($_POST['rdoGioiTinh'] == 'Nam') {
                $GT = Nam ;
            } else {
                $GT = Nu;
            }
            //kiểm tra firtname
            if ($_POST['txtFirtName'] == NUL || $_POST["txtLastName"] == null) {
                print "Xin vui lòng nhập đầy đủ các thông tin. <a href='javascript:history.go(-1)'>Nhấp vào đây để quay trở lại</a>";
                exit;
            }
            $sql = "UPDATE users SET location_id=$idLocation,fname='$FirtN',lname='$LastN',sex='$GT'where id=2";
            if (!$conn->query($sql)) {
                die('Error: ');
            }
            echo " Th�m tha?nh c�ng </br>";
        } else {
            $_POST["txtfname"] = $_POST["txtlname"] = "";
        }
        $sql1 = $conn->query("SELECT * FROM locations");
        mysql_query("set names'UTF8'");
        $location = mysqli_fetch_all($sql1, MYSQLI_ASSOC);
        ?>       
        <form action="" method="post" class="form-horizontal">
            <div class="example" >
                <div class="container">
<!--                    <div class="text-center">
                        <b>
                            Email:&nbsp;<input class="text-center" placeholder="email" type="text" name="txtEmail"/> 
                            Mật Khẩu:&nbsp;<input class="text-center" placeholder="Mật Khẩu" type="password" name="txtMK"/> 
                            <b>
                                <br>
                                <br>
                                <button class="btn-primary" name="btnDN">Đăng Nhập</button>
                                </div>-->
                                <div class="row">
                                    <h2 class="text-center">CẬP NHẬT THÔNG TIN</h2>
                                    <table class="table">
                                        <tr>
                                            &nbsp;
                                        </tr>
                                        <thead>
                                            <tr>
                                                <th class="text-right"><b>Firt Name:&nbsp;</b></th>
                                                <th><input class="text-center" placeholder="Tên" type="text" value='<?php echo $LayTT["fname"] ?>' name="txtFirtName"/> </th>                        
                                            </tr>
                                            <tr >
                                                <td class="text-right"><b>  Last Name:&nbsp;</b></td>
                                                <td><input class="text-center" placeholder="Họ" type="text" value='<?php echo $LayTT["lname"] ?>' name="txtLastName"/></td>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td class="text-right"><b>Giới Tính:  </b></td>
                                                <td>
                                                <?php 
                                                
                                                if($LayTT["sex"]=="Nam")
                                                { 
                                                    echo $LayTT['sex'];
                                                    $sexNam=true;
                                                    $sexNu=FALSE;
                                                    echo '<input type="radio" name="rdoGioiTinh" value="Nam" checked="'.$sexNam.'"/>Nam';  
                                                    echo '<input type="radio" name="rdoGioiTinh" value="Nu" checked="'.$sexNu.'"/>Nữ';
                                                }
                                                else {
                                                   $sexNam=FALSE;
                                                    $sexNu=TRUE;
                                                    echo '<input type="radio" name="rdoGioiTinh" value="Nam" checked="'.$sexNam.'"/>Nam';  
                                                    echo '<input type="radio" name="rdoGioiTinh" value="Nu" checked="'.$sexNu.'"/>Nữ';
                                                }
                                                    ?>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="text-right"> Vị trí </td>
                                                <td> <select name ="id" >
<?php
foreach ($location as $value) {
    
    echo '<option '.'value="' . $value['id'] . '">' . $value['name'] . '</option>';
}
?> 
                                                    </select></td> 
                                            </tr>
                                            <tr>
                                                <td>                               
                                                </td>
                                                <td class="text-left">
                                                    <button  class="btn btn-primary" name="btnLuu">Lưu<i class="fa fa-sign-in"></i></button>
                                                    <button class="btn btn-primary" name="btnLamMoi">Làm Mới</button>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                                </div>

                                </div>
                                </form>
                                </body>
                                </html>
